<template>
  <div>
    <div class="show">
        <div class="show1" >
          <img ref="showing" src="" id="showimg" style="margin-left: 1px;margin-top: 3px">
        </div>
        <br>
        <input multiple="multiple" id="file" ref="file" @click="changepic(this)" type="file" name="userpic"
               style="margin-left: 10%;height: 50px; display:inline-block;width: 50%;">
        <el-button plain @click="subchangepic()"  style="height: 40px;position: relative; margin-left:15%;">确定</el-button>
    </div>
  
  </div>
 
</template>

<script>
import { Message } from "element-ui";

export default {
 
  name: "imageUp",
  data(){
    return {
      user: this.$TestData.user,
      
      filename: null,
      f64: null,
      userImage: "",
      
      Message:{
				message:"" ,
				type: "",
				duration: 5 * 1000,
			},
    }
  },



  methods:{
    
    changepic() {
      document.getElementById('file').onchange = function () {
        var imgFile = this.files[0];
        var fr = new FileReader();

        fr.onload = function () {
          let showing = document.getElementById('showimg')
          let img = fr.result;
          this.f64 = img;
          this.filename = imgFile.name
          showing.src = img;
          showing.style.height = "220px";
          showing.style.width = "220px";
          showing.style.borderRadius="200px"
        };
        fr.readAsDataURL(imgFile);
      }
      },
      
    subchangepic(){
      this.$confirm("确定修改吗？", "修改", {
				comfirmButtonText: "确定",
				cancelButtonText: "取消",
				type: "warning",
			})
      .then(() => {
      var tokenObject = this.$Storage.getItemForLs(this.$TestData.TOKEN_OBJECT_KEY);
      const token=this.$Storage.getItemForLs(this.$TestData.TOKEN_KEY);
      if(this.$refs.file.files[0]!=null){
        this.f64 = this.$refs.file.files[0]
        
        let param = new FormData();
        param.append("file",this.f64);
        var self=this;
        $.ajax({
          url: "http://127.0.0.1:8000/api/rentuser/image/"+tokenObject.aud,
          type: 'post',
          contentType : false,
          processData : false,
          headers: {
             
            "token": token
          },
          data: param,
         
          success:function(res){
            if(res.status==200){
             Message({
				message: res.message,
				type: "success",
				duration: 5 * 1000,
			});
      self.user.userImage="http://127.0.0.1:8000"+res.data;
      location.reload();
            }
          }

        })

      }

     })
				.catch(() => {});
    },
   
   

  },
 
}
</script>

<style scoped>


button {
  margin-left: 70%;
  width: 15%;
  height: 35px;
  border-width: 0px;
  border-radius: 3px;
  background: #1E90FF;
  cursor: pointer;
  outline: none;
  font-family: Microsoft YaHei;
  color: white;
  font-size: 17px;
}
.show{
  margin: 100px auto;
  width: 80%;
  height: 450px;
  border: 5px solid #18a0ec;
  transition: all 0.9s;
  border-radius: 10px;

}
.show1{
  margin: 50px auto;
  width: 222px;
  height: 226px;
  border: 5px solid #18a0ec;
  transition: all 0.9s;
  border-radius: 150px;

}

.show1:hover{
  box-shadow: 0px 15px 30px rgba(0, 0, 0, 0.4);
  margin-top: 90px;
}

.show:hover{
  box-shadow: 0px 15px 30px rgba(0, 0, 0, 0.4);
  margin-top: 90px;
}

.texti{
  border: 1px solid #ccc;
  padding: 13px 14px;
  width: 30%;

  font-size: 14px;
  font-weight: 300;

  border-radius: 5px; /* 边框半径 */
  background: white; /* 背景颜色 */
  cursor: pointer; /* 鼠标移入按钮范围时出现手势 */
  outline: none; /* 不显示轮廓线 */


}
.texti:focus{
  border-color: #1e88e1;
  outline: 0;
  -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
  box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)
}
textarea {
  resize: none;

}
</style>